package com.xd.study.activity;

import android.app.Activity;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.ToggleButton;

import com.xd.study.R;

/**
 * Created by DGF on 2015/4/22.
 */
public class ToggleButtonActivity extends Activity {

    private ImageView imageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.togglebutton);

        ToggleButton toggleButton=(ToggleButton)this.findViewById(R.id.toggleButton);
        imageView = (ImageView)this.findViewById(R.id.imageView);

        toggleButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                imageView.setBackgroundResource(isChecked ? R.drawable.toggle_button_on : R.drawable.toggle_button_off);
            }
        });

    }
}
